package com.sky.robot.controller;

import com.sky.robot.service.SkyRobotService;
import com.sky.robot.utils.JSONUtils;
import com.sky.robot.utils.Result;
import com.sky.robot.vo.CodeGeneratorRequestVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;


@RestController
@RequestMapping("/core/skyRobot")
public class SkyRobotController {

    @Autowired
    private SkyRobotService skyRobotService;


    @PostMapping("/sendPrompt")
    public Result<?> sendPrompt(@RequestBody Map<String, Object> promptMap){
        return Result.success(skyRobotService.send(promptMap));
    }

    @PostMapping("/executorPy")
    public Result<?> executorPy(@RequestBody Map<String, Object> promptMap) throws IOException, InterruptedException {
        return Result.success(skyRobotService.executorPy(promptMap));
    }


    /**
     * 加载配置项
     */
    @GetMapping("/getInitConfig")
    public Result<?> getInitConfig(
            @RequestParam("functionId") String functionId
    ) {
        Map<String, Object> result = skyRobotService.getInitConfig(functionId);
        return Result.success(result);
    }

    /**
     * 保存配置项
     */
    @PostMapping("/saveInitConfig")
    public Result<?> saveInitConfig(@RequestBody Map<String, Object> map) {
        Map<String, Object> result = skyRobotService.saveInitConfig(map);
        return Result.success(result);
    }

    /**
     * 生成后台代码逻辑
     */
    @PostMapping("/code-generator")
    @ResponseBody
    public Result<Void> codeGenerator(@RequestBody @Validated CodeGeneratorRequestVo requestVo) {
        return skyRobotService.codeGenerator(requestVo);
    }

    @PostMapping("/vue")
    public Result<?> analyseVue() {

        return Result.success();
    }

}
